//
//  cPhonePSWController.m
//  Ten
//
//  Created by anfuer on 2018/8/21.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "cPhonePSWController.h"
#import "UIButton+countDown.h"
@interface cPhonePSWController ()
{
    
}
@property (weak, nonatomic) IBOutlet UILabel *titleLb1;
@property (weak, nonatomic) IBOutlet UITextField *tsf1;
@property (weak, nonatomic) IBOutlet UITextField *tsf2;
@property (weak, nonatomic) IBOutlet UIButton *codeBtno;
@property (weak, nonatomic) IBOutlet UIView *hidenView;
@property (weak, nonatomic) IBOutlet UITextField *tsf3;
@property (weak, nonatomic) IBOutlet UILabel *lb1;

@end

@implementation cPhonePSWController

- (void)viewDidLoad {
    [super viewDidLoad];
    _hidenView.hidden=[_type isEqualToString:@"phone"]?YES:NO;
    _titleLb1.text=[_type isEqualToString:@"phone"]?@"更换手机号":[_type isEqualToString:@"bangphone"]?@"绑定手机号":[_type isEqualToString:@"forgit"]?@"重置密码":@"更换密码";
    _lb1.text=[_type isEqualToString:@"phone"]?@"新手机号":@"手机号";
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    if ([_type isEqualToString:@"passwork"]) {
        _tsf1.userInteractionEnabled=NO;
        _tsf1.text=WXGStr([FuncPublic GetDefaultInfo:@"myphone"]);
    }
//
    
}
- (IBAction)SendCodeBtna:(UIButton *)sender {
    [FuncPublic getData:self parameters: [_type isEqualToString:@"bangphone"]?@{@"phone":_tsf1.text,@"logintype":@"weixin"}:@{@"phone":_tsf1.text,@"type":[_type isEqualToString:@"forgit"]||[_type isEqualToString:@"passwork"]?@"4":@"3"} RequestUrl: [_type isEqualToString:@"bangphone"]?CsendMessage:get_code success:^(NSDictionary *acountInfo) {
       
        [WSProgressHUD showImage:nil status:@"发送成功"];
        [_tsf2 becomeFirstResponder];
        _codeBtno.countDownFormat=@"重新发送%ds";
        [_codeBtno countDownWithTimeInterval:49];
    }];
}
- (IBAction)Btna:(id)sender {
    NSDictionary*dic;
    if ([_type isEqualToString:@"phone"]) {
        dic=@{@"phone":_tsf1.text,@"code":_tsf2.text};
    }else if ([_type isEqualToString:@"bangphone"])
    {

        if ([_bangDic[@"logintype"] isEqualToString:@"qq"]) {
            dic=@{@"logintype":@"qq",@"phone":_tsf1.text,@"code":_tsf2.text,@"openid":_bangDic[@"openid"],@"nickname":_bangDic[@"name"],@"headimg":_bangDic[@"iconurl"],@"sex":[_bangDic[@"gender"]isEqualToString:@"男"]?@"1":@"2",@"password":_tsf3.text};
        }else{
dic=@{@"logintype":@"weixin",@"phone":_tsf1.text,@"code":_tsf2.text,@"openid":_bangDic[@"openid"],@"nickname":_bangDic[@"nickname"],@"headimg":_bangDic[@"headimgurl"],@"sex":_bangDic[@"sex"],@"password":_tsf3.text};
        }
    }
    else
    {
        dic=@{@"phone":_tsf1.text,@"code":_tsf2.text,@"password":_tsf3.text};
    }
    

    [FuncPublic getData:self parameters:dic RequestUrl:[_type isEqualToString:@"phone"]? Xchange_phone: [_type isEqualToString:@"bangphone"]? CauthReg:Xchange_pass success:^(NSDictionary *acountInfo) {
        
       [WSProgressHUD showImage:nil status:@"修改成功"];
        if ([_type isEqualToString:@"bangphone"]) {
            [FuncPublic SaveDefaultInfo:@"1" Key:@"DENGLU"];
            [FuncPublic SaveDefaultInfo:acountInfo[@"token"] Key:@"token"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
